package com.corpcredit.webapp.action;

import java.io.Serializable;
import java.util.Date;

import com.corpcredit.Constants;
import com.corpcredit.model.GlryShjz;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class GlryShjzForm extends BasePage implements Serializable {
    private GenericManager<GlryShjz, Long> glryShjzManager;
    private GlryShjz glryShjz = new GlryShjz();
    private Long id;

    public void setGlryShjzManager(GenericManager<GlryShjz, Long> glryShjzManager) {
        this.glryShjzManager = glryShjzManager;
    }

    public GlryShjz getGlryShjz() {
        return glryShjz;
    }

    public void setGlryShjz(GlryShjz glryShjz) {
        this.glryShjz = glryShjz;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        glryShjzManager.remove(glryShjz.getId());
        addMessage("glryShjz.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            glryShjz = glryShjzManager.get(id);
        } else {
            glryShjz = new GlryShjz();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (glryShjz.getId() == null || glryShjz.getId() == 0);
        
        //dwtz.setJbqk(jbqk);
        glryShjz.setUsername(getRequest().getRemoteUser());
        glryShjz.setOptdate(new Date());
        glryShjz.setOperation(isNew?Constants.OPERATION_ADD:Constants.OPERATION_UPDATE);
        

        glryShjzManager.save(glryShjz);

        String key = (isNew) ? "glryShjz.added" : "glryShjz.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
           	
     	   this.id=this.glryShjz.getId();
              return edit();

        }
    }
} 